<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');   

    require_once ($application_folder."/libraries/MY_Controller.php"); 
    class Navigator extends MY_Controller {

        var $data = array();

        function __construct()
        {
            parent::__construct();
        }

        function index() { show_404(); } 

        function seo_data($rows){

            $this->data['seo_title'] = '';
            $this->data['seo_description']='';
            $this->data['seo_keywords']='';

            foreach ($rows as $row)
            {
                $this->data['seo_title'] = $row->title;
                $this->data['seo_description']=$row->description;
                $this->data['seo_keywords']=$row->keywords;
            }

        }        

        function core_index($page=NULL,$sub=NULL,$upsub=NULL){

            $this->data['page'] = $page;
            $this->data['sub'] = $sub;
            $this->data['upsub'] = $upsub;

            $this->data['lang'] = $this->lang_ses->getlang();    

            $url;

            if(($sub=='')&&($upsub=='')){ 

                $url = 'site/'.$page;
                $this->asset->flag('page');

            }else if($upsub==''){ 

                    $url = 'site/'.$page.'/'.$sub;
                    $this->asset->flag('sub');

                }else{

                    $url = 'site/'.$page.'/'.$sub.'/'.$upsub;
                    $this->asset->flag('upsub');

            }

            $this->asset->initialze_assets($page, $sub, $upsub);
            
            $this->load->model('sitem');
            $this->data['row'] = $this->sitem->read($page, $sub, $upsub);
            
            $this->layout->view($url, $this->data);


        }

        function navigate($page=NULL,$data=NULL)
        {
            if ($data!=NULL){
                $this->data = array_merge((array)$this->data, (array)$data);   
            }

            /*
            *     Explode
            *     last sub page /
            *     get assets        
            */             


            $p = explode ('/', $page);
            $pg = $p[count($p)-1];
            //$this->data['page'] = $pg;

            $this->asset->getassets($pg, $page);
            $this->dataload->getdata( $this->data['sub'], $this);

            $this->layout->view($page, $this->data);            
        }

        function navigate_cms($page=NULL,$data=NULL){
            if ($data!=NULL){
                $this->data = array_merge((array)$this->data, (array)$data);   
            }

            $p = explode ('/', $page);
            $pg = $p[count($p)-1];
            $this->data['page'] = $pg;

            //$this->asset->getassets($pg, $pg);
            //$this->dataload->getdata($pg, $this);

            $this->layout->view($page, $this->data);
        }

        function json_encode_get($html)
        {
            if(isset($_GET['jsoncall'])) {

                $html = preg_replace(
                array('/\n/','/\r/','/\t/'),
                array(''),
                $html);
                echo $_GET['jsoncall'] . '(' . json_encode(array('html'=>$html)) . ');';

            }else {
                echo json_encode(array('html',$html));
            }
        }
    }
?>